home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Merciful 2
/
Merciful - Disc 2.iso
/
software
/
d
/
dialupv3.06.lha
/
dialup
/
util.c
< prev
Wrap
C/C++ Source or Header
|
1996-01-29
|
4KB
|
188 lines
#include "dialup.h"
extern BPTR mystderr;
extern const UBYTE *prgname;
extern struct IOExtSer *serialIOReq;
extern struct timerequest *timereq;
extern BPTR repfile;
extern UBYTE *rxbuffer;
extern LONG arg[];
extern struct argspec argtab[];
/* check for second start: */
BOOL
unique(struct MsgPort *serialport)
{
Disable();
if( serialport = FindPort(SERPORTNAME) )
{
Signal( serialport->mp_SigTask, SIGBREAKF_CTRL_C );
Enable();
DisplayBeep(NULL);
return(FALSE);
};
Enable();
_OK_;
}
/* init defaults for parameters: */
void
initDefaultsAndTemplate(UBYTE *wptr)
{
enum argnames argcnt = A_CMD; /* first command */
while ( 1 )
{
wptr += sprintf(wptr, argtab[argcnt].name);
arg[argcnt] = argtab[argcnt].deflt;
if ( A_ALL == ++argcnt )
break;
*wptr++ = ',';
}
}
#define MAXARGNAMELEN 30
/* build defaults template: */
BOOL
initDefaultsTemplate(UBYTE *wptr, LONG argd[])
{
UBYTE argnamebuf[MAXARGNAMELEN];
enum argnames argcnt = A_CMD; /* first command */
while ( 1 )
{
UBYTE *sptr;
if ( strlen(argtab[argcnt].name) > MAXARGNAMELEN - 3)
return(FALSE);
strcpy( argnamebuf, argtab[argcnt].name );
if ( sptr = strchr(argnamebuf, '/' ) )
{
sptr[1] = 'S';
sptr[2] = '\0';
}
wptr += sprintf(wptr, argnamebuf );
argd[argcnt] = NULL;
if ( A_END == ++argcnt )
break;
*wptr++ = ',';
};
_OK_;
}
void
showdefaults(LONG argd[])
{
enum argnames argcnt;
BOOL anyopt = FALSE;
for ( argcnt = A_END - 2; argcnt > A_CMD || !anyopt ; argcnt--)
{
if ( argd[argcnt] || argd[A_ALL] )
{
UBYTE pnc = 0;
FPrintf(Output(), "%s: ", argtab[argcnt].name);
if ( strstr( argtab[argcnt].name, "/N" ) )
FPrintf(Output(), "%d\n", *(LONG *)arg[argcnt] );
else if ( strstr( argtab[argcnt].name, "/M" ) )
{
while ( ((UBYTE **)arg[argcnt])[pnc] )
FPrintf(Output(), "%s ", ((UBYTE **)arg[argcnt])[pnc++]);
FPrintf(Output(), "\n");
}
else if ( strstr( argtab[argcnt].name, "/S" ) )
FPrintf(Output(), "%s\n", arg[argcnt] ? "ON" : "OFF" );
else
FPrintf(Output(), "%s\n", arg[argcnt] ? (UBYTE *)arg[argcnt] : "*NO DEFAULT*" );
anyopt = TRUE;
};
};
}
BOOL
initSerialLine(struct SP *serpara)
{
/* setting serial parameters ?*/
if ( ! arg[A_NSI] ) /* if modem is online it doesn't autodetect baudrate on AT and the parameters should be correct anyway */
{
serialIOReq->IOSer.io_Command = SDCMD_SETPARAMS;
serialIOReq->io_SerFlags &= ~SERF_PARTY_ON;
serialIOReq->io_SerFlags |= (SERF_RAD_BOOGIE | SERF_XDISABLED);
if ( serpara->serHWHS )
serialIOReq->io_SerFlags |= SERF_7WIRE;
serialIOReq->io_ExtFlags = 0;
serialIOReq->io_Baud = serpara->serBaudRate;
VERIFY ( DoIO((struct IORequest *)serialIOReq) == NULL );
};
/* flush device */
serialIOReq->IOSer.io_Command = CMD_FLUSH;
VERIFY ( DoIO((struct IORequest *)serialIOReq) == NULL)
for(;;) /* sink all incomming data to NIL: */
{
serialIOReq->IOSer.io_Command = SDCMD_QUERY;
DoIO((struct IORequest *)serialIOReq);
if( serialIOReq->IOSer.io_Actual == 0 )
break;
serialIOReq->IOSer.io_Command = CMD_READ;
serialIOReq->IOSer.io_Length = serialIOReq->IOSer.io_Actual;
serialIOReq->IOSer.io_Data = (APTR)rxbuffer;
VERIFY ( DoIO((struct IORequest *)serialIOReq) == NULL );
Delay(9); /* wait for the line to get quiet */
};
_OK_
}
void
buildMatchStringArray( UBYTE *pattern, UBYTE *buf, UBYTE *msa[] )
{
USHORT mcnt;
UBYTE *spt;
/* I want to modify the string, but the prg should be residentable (pure)! */
strcpy(buf, pattern);
/* build match pointer array of string with matches: */
for (mcnt = 0; mcnt < MAXMATCHSTRING - 1; mcnt++)
{
if ( !( spt = strrchr( buf , '|' ) ) )
break;
*spt = '\0';
msa[mcnt] = spt + 1;
};
msa[mcnt] = buf;
msa[mcnt + 1] = NULL;
}
UBYTE *
matchString( UBYTE *string, UBYTE *msa[])
{
UBYTE *sptr;
while ( *msa && !stcpm(string, *msa, &sptr) )
msa++;
return ( *msa ? sptr : NULL );
}
UBYTE *
sStrMatch(UBYTE *string, UBYTE *pattern, UBYTE *buf)
{
UBYTE *msa[MAXMATCHSTRING];
buildMatchStringArray(pattern, buf, msa);
return( matchString( string, msa) );
}